import { IRespose } from "@/configs/request"
/*********
 * 查询需要点亮的菜单父级 根据路径获取子路由的所有父级菜单组
 * 根据路径来一级一级匹配左侧菜单
 * 路由权限只做左侧菜单
 * ********/
export const findParentPaths = (pathname: any) => {
  let slicePathname = pathname.slice(1)
  let splitPathname = slicePathname.split("/")
  let defaultOpenKeys = []
  if (splitPathname.length > 1) {
    // splitPathname.pop();//删除最后一个
    let str = ""
    splitPathname.forEach((name: any, index: number, arr: any) => {
      str = str + "/" + arr[index]
      defaultOpenKeys.push(str)
    })
  } else {
    defaultOpenKeys.push("/" + splitPathname[0]) // 不管哪个菜单，都点亮第一个
  }
  return defaultOpenKeys
}


// 不写then、catch


export const to = async <R>(promise: Promise<R>): Promise<[any, R]> => {
  try {
    const res = await promise
    return Promise.resolve([null, res])
  } catch (err) {
    return Promise.resolve([err, null as any])
  }
}
